package com.ref;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * @version 1.0
 * @Author: 许啸林
 * @Date: 2021/9/9 15:36
 */
public class Ref01 {
    public static void main(String[] args) throws Exception {
        refObj();
    }
    public static void refObj() throws Exception {
        Properties properties = new Properties();
        properties.load(new FileInputStream("src\\obj.properties"));
        String objName = properties.getProperty("objName");
        String methodName = properties.getProperty("methodName");
        Class<?> obj = Class.forName(objName);
        Object objInstance = obj.newInstance();
        Method method = obj.getMethod(methodName);
        // method filed constructor都有访问检查,设置关闭可以提升性能
        method.setAccessible(false);
        method.invoke(objInstance);
    }
}
